//
//  ShellLiquidationCell.m
//  ShellWallert
//
//  Created by lvzhao on 2020/5/24.
//  Copyright © 2020 VV. All rights reserved.
//

#import "ShellLiquidationCell.h"
#import "ShellLiquidationModel.h"

@interface ShellLiquidationCell ()

//数量
@property (nonatomic,strong) UILabel *amountLab;

//时间
@property (nonatomic,strong) UILabel *timeLab;

//状态
@property (nonatomic,strong) UIButton *statueBtn;

@property (nonatomic,strong) ShellLiquidationModel *liquidationModel;

@end

@implementation ShellLiquidationCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
                
        self.backgroundColor = COLOR_BACKGROUND;
        [self setupView];
    }
    return self;
}


#pragma mark - setupView
- (void)setupView{
    
    //背景
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = COLOR_TINT;
    contentView.cornerRadius = 6;
    [self.contentView addSubview:contentView];
    contentView.cornerRadius = 8;
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(K_SCREENWIDTH - 30);
        make.height.mas_equalTo(60);
    }];
    
    self.amountLab = [UILabel lz_labelWithText:@"" fontSize:k_textFont(14) color:UIColorHex(0xFFFFFF)];
    [contentView addSubview:self.amountLab];
    [self.amountLab mas_makeConstraints:^(MASConstraintMaker *make) {
          make.top.mas_equalTo(10);
          make.left.mas_equalTo(10);
          make.width.mas_equalTo(200);
          make.height.mas_equalTo(20);
      }];
 
    
    self.timeLab = [UILabel lz_labelWithText:@"" fontSize:k_textFont(12) color:UIColorHex(0x678DA8)];
    [contentView addSubview:self.timeLab];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.amountLab.mas_bottom);
        make.left.mas_equalTo(10);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(20);
    }];
    
    self.statueBtn = [UIButton lz_buttonTitle:@"" titleColor:UIColorHex(0x8D99B2) fontSize:13];
    [self.statueBtn setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
    [self.statueBtn setTitleColor:UIColorHex(0x8D99B2) forState:UIControlStateDisabled];
    self.statueBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
    
    UIImage *norImage = [UIImage imageWithColor:UIColorHex(0x0D3354) size:CGSizeMake(78, 25)];
    UIImage *selectImage = [UIImage gradientImageWithColors:@[UIColorHex(0x65DFFE),UIColorHex(0x22C6FE)] rect:CGRectMake(0, 0, 78, 25)];
    
    [self.statueBtn setBackgroundImage:norImage forState:UIControlStateDisabled];
    [self.statueBtn setBackgroundImage:selectImage forState:UIControlStateNormal];
    [contentView addSubview:self.statueBtn];
    [self.statueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(contentView);
        make.right.mas_equalTo(-10);
        make.width.mas_equalTo(78);
        make.height.mas_equalTo(25);
    }];
    self.statueBtn.cornerRadius = 4;
    
    @weakify(self);
    [[self.statueBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self.viewModel liquidation:self.liquidationModel];
    }];
    
}
    

- (void) setModelObject:(id)modelObject{
    self.liquidationModel = modelObject;
    ShellLiquidationModel *liquidationModel = modelObject;
    NSString *amount = [NSString stringWithFormat:@"%@",liquidationModel.amount].saveDecimal;
    self.amountLab.text = [NSString stringWithFormat:@"%@USDT",amount];
    
    /*
    10:清算
    20：待结算
    30：已结算
     */

    NSInteger statue = [liquidationModel.status intValue];
    switch (statue) {
        case 10:
        {
            self.statueBtn.enabled = YES;
            [self.statueBtn setTitle:LZLocalizedString(@"清算") forState:UIControlStateNormal];
        }
            break;
            case 20:
             {
                 self.statueBtn.enabled = NO;
                 [self.statueBtn setTitle:LZLocalizedString(@"待结算") forState:UIControlStateNormal];

             }
                 break;
        case 30:
             {
                 self.statueBtn.enabled = NO;
                 [self.statueBtn setTitle:LZLocalizedString(@"已结算") forState:UIControlStateNormal];
             }
                 break;

        default:
            self.statueBtn.enabled = YES;
            break;
    }
    
    self.timeLab.text = [NSString stringWithFormat:LZLocalizedString(@"可退出时间%@"),liquidationModel.outTime];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
